package com.example.su_shi_tan_core

import android.content.Context
import android.content.Intent
import androidx.work.OneTimeWorkRequest
import androidx.work.PeriodicWorkRequest
import androidx.work.WorkManager
import com.alibaba.android.arouter.launcher.ARouter
import com.example.su_shi_tan_bas_lib.global.AppGlobals
import com.example.su_shi_tan_core.arouter.AppARouter
import com.example.su_shi_tan_core.db.LogInTokenManager
import java.util.concurrent.TimeUnit

fun getUserInfo(context: Context) {
//    val mUserInfo=PeriodicWorkRequest.Builder(UserInfoDataWorker::class.java,10, TimeUnit.SECONDS)
//        .build()
//    val mSignUser=PeriodicWorkRequest.Builder(SignUserWorker::class.java,10, TimeUnit.SECONDS)
//
//        .build()
//    WorkManager.getInstance(context)
//        .enqueue(listOf(mUserInfo,mSignUser))
    WorkManager.getInstance(context)
        .beginWith(
            OneTimeWorkRequest.Builder(UserInfoDataWorker::class.java)
                .build(),

        ).then(
            OneTimeWorkRequest.Builder(SignUserWorker::class.java)
                .build(),
        ).then(
            OneTimeWorkRequest.Builder(AppUpDataWorker::class.java)
                .build(),
        )
        .enqueue()
}

fun reStartMainActivity(){
    ARouter.getInstance().build(AppARouter.Main_Activity)
        .withFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
        .navigation(AppGlobals.getApplication())
}

fun signOut() {

    LogInTokenManager.tokenManager.signOutUserInfoWrapper()

    reStartMainActivity()
}